package com.learn.aop;

import com.learn.annotation.Secure;
import com.learn.service.IAppointService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AppointAop {

    // 切点范围
    @Pointcut("execution(* com.learn.service..IAppointService+.*(..))")
    public void pointcut() {
    }

//    @Before("pointcut() && args(param)")
//    @Before("execution(* com.learn.service..IAppointService+.say(*)) && args(param)")
//    public void before1(String param) {
//        System.out.println("===param:" + param);
//    }

    @Pointcut(value = "args(param)", argNames = "param")
    private void pointcut1(String param) {
    }

    @Pointcut(value = "@annotation(secure)", argNames = "secure")
    private void pointcut2(Secure secure) {
    }

    @Before(value = "execution(* com.learn.service..IAppointService+.say(*)) && args(param)", argNames = "param")
    //明确指定了
    public void before1(String param) {
        System.out.println("===param:" + param);
    }

    @Before(value = "execution(* com.learn.service..IAppointService+.say(*)) && args(param)", argNames = "jp, param")
    //明确指定了
    public void before1(JoinPoint jp, String param) {
        System.out.println("===JoinPoint:" + jp.getKind());
        System.out.println("===param:" + param);
    }

    @Before(value = "pointcut() && args(param) && this(service) && @annotation(secure)", argNames = " jp, param, service, secure")
    public void before2(JoinPoint jp, String param, IAppointService service, Secure secure) {
        service.logInfo("==before==");
        System.out.println("===JoinPoint:" + jp.getKind());
        System.out.println("===param:" + param);
        System.out.println("===secure:" + secure.value());
    }

    @Before(value = "pointcut1(param) && pointcut2(secure)",
            argNames = "jp, param, secure")
    public void before3(JoinPoint jp, String param, Secure secure) {
        System.out.println("before3");
    }
}
